class Solution {
public:
    string discountPrices(string sentence, int discount) {
        int n = sentence.size();
        string t;
        for (int i = 0; i < n; i++)
        {
            int j = i;
            if (sentence[j] <= '9' && sentence[j] >= '0'
                && j > 0 && sentence[j - 1] == '$' && (j - 2 == -1 || sentence[j - 2] == ' '))
            {
                string tmp;
                while (sentence[j] <= '9' && sentence[j] >= '0' &&
                    (j < n || sentence[j] != ' '))
                    tmp += sentence[j++];
                double sum = stod(tmp) - stod(tmp) * discount * 0.01;
                char buf[50];
                sprintf(buf, "%.2lf", sum);
                cout << buf << endl;
                if (j == n || sentence[j] == ' ')
                {
                    t += buf;
                    i = j;
                }
            }

            if (i < n) t += sentence[i];
        }
        return t;
    }
};